var prefix = "/sys/job";
$(document).ready(function () {
    validateRule();
});

$.validator.setDefaults({
    submitHandler: function () {
        save();
    }
});

function save() {
    $.ajax({
        cache: true,
        type: "POST",
        url: prefix + "/add",
        data: $('#jobForm').serialize(),
        async: false,
        error: function () {
            parent.layer.msg("Connection error");
        },
        success: function (data) {
            if (data.code === 0) {
                parent.layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);
            } else {
                parent.layer.msg(data.msg);
            }
        }
    });
}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#jobForm").validate({
        rules: {
            jobName: {
                required: true
            }, baseMoney: {
                required: true
            }
        },
        messages: {
            jobName: {
                required: icon + "请输入岗位名称"
            }, baseMoney: {
                required: icon + "请输入基础绩效"
            }
        }
    });
}